//
//  TTUserModel.m
//  ExhibitionHall
//
//  Created by 王洋 on 2019/6/15.
//  Copyright © 2019 王洋. All rights reserved.
//

#import "TTUserModel.h"

@interface TTUserModel ()

@end

@implementation TTUserModel

+ (TTUserModel *)sharedObject {
    static TTUserModel *shareInstance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken,^{
        shareInstance = [TTUserModel new];
    });
    return shareInstance;
}

- (void)initialization {
        
    //normal
    [self.userModelDefault setValue:@"" forKey:@"TT_phone"];
    [self.userModelDefault setValue:@"" forKey:@"TT_token"];
    [self.userModelDefault setValue:@"" forKey:@"TT_roleId"];
    [self.userModelDefault setValue:@"" forKey:@"TT_cardId"];
    [self.userModelDefault setValue:@"" forKey:@"TT_userId"];
    [self.userModelDefault setValue:@"" forKey:@"TT_authWx"];
    [self.userModelDefault setValue:@"" forKey:@"TT_isAgent"];
    [self.userModelDefault setValue:@"" forKey:@"TT_userName"];
    [self.userModelDefault setValue:@"" forKey:@"TT_auditPass"];
    [self.userModelDefault setValue:@"" forKey:@"TT_authPhone"];
    [self.userModelDefault setValue:@"" forKey:@"TT_avatarUrl"];
    [self.userModelDefault setValue:@"" forKey:@"TT_companyName"];
    
    [self.userModelDefault setValue:@[] forKey:@"auths"];

    
    //IM
    [self.userModelDefault setValue:@"" forKey:@"TT_identifier"];
    [self.userModelDefault setValue:@"" forKey:@"TT_userSig"];
    [self.userModelDefault setValue:@"" forKey:@"TT_appidAt3rd"];
    
    [self.userModelDefault setValue:@"0" forKey:@"TT_authPhone"];
    [self.userModelDefault setValue:@"0" forKey:@"TT_authWx"];
    [self.userModelDefault synchronize];
}

- (void)fillUserModelWithDic:(NSMutableDictionary *)userDic {
    
    //normal
    [self.userModelDefault setValue:[userDic valueForKey:@"phone"] forKey:@"TT_phone"];
    [self.userModelDefault setValue:[userDic valueForKey:@"token"] forKey:@"TT_token"];
    [self.userModelDefault setValue:[userDic valueForKey:@"roleId"] forKey:@"TT_roleId"];
    [self.userModelDefault setValue:[userDic valueForKey:@"cardId"] forKey:@"TT_cardId"];
    [self.userModelDefault setValue:[userDic valueForKey:@"userId"] forKey:@"TT_userId"];
    [self.userModelDefault setValue:[userDic valueForKey:@"authWx"] forKey:@"TT_authWx"];
    [self.userModelDefault setValue:[userDic valueForKey:@"isAgent"] forKey:@"TT_isAgent"];
    [self.userModelDefault setValue:[userDic valueForKey:@"userName"] forKey:@"TT_userName"];
    [self.userModelDefault setValue:[userDic valueForKey:@"auditPass"] forKey:@"TT_auditPass"];
    [self.userModelDefault setValue:[userDic valueForKey:@"authPhone"] forKey:@"TT_authPhone"];
    [self.userModelDefault setValue:[userDic valueForKey:@"avatarUrl"] forKey:@"TT_avatarUrl"];
    [self.userModelDefault setValue:[userDic valueForKey:@"companyName"] forKey:@"TT_companyName"];
    
//    [self.userModelDefault setValue:@"eJw1zMEKgkAUheF3mXXIdcbrDEKbiKiIJG2hyzGnuFk2qFRT9O6J1vJ8B-43229S724aFjHuAZsMm0pTd3SkgX0UgCEoJf53W1baWipZ5AcAIoQA5fiYp6XG9I6IHABG7eg6mFIoUSj1q9Cpr19cfMhctXIhN*c6jYttss4K*9B6keSv20620mqdLGfzfMo*X6YGMoo_" forKey:@"TT_userSig"];
//
//    [self.userModelDefault setValue:@"15305608830" forKey:@"TT_identifier"];
    
    [self.userModelDefault setValue:[userDic valueForKey:@"chatPassword"] forKey:@"TT_userSig"];
    [self.userModelDefault setValue:[userDic valueForKey:@"chatUserId"] forKey:@"TT_identifier"];
    [self.userModelDefault setValue:@"1400360457" forKey:@"TT_appidAt3rd"];
    
    BOOL authWx = [[userDic valueForKey:@"authWx"] boolValue];
    if (authWx) {
        [self.userModelDefault setValue:@"1" forKey:@"TT_authWx"];
    } else {
        [self.userModelDefault setValue:@"0" forKey:@"TT_authWx"];
    }
    
    BOOL authPhone = [[userDic valueForKey:@"authPhone"] boolValue];
    if (authPhone) {
        [self.userModelDefault setValue:@"1" forKey:@"TT_authPhone"];
    } else {
        [self.userModelDefault setValue:@"0" forKey:@"TT_authPhone"];
    }
    
    [self.userModelDefault synchronize];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"HY_LoginSuccess" object:nil userInfo:nil];

}

- (NSString *)companyName {
    NSString *TT_companyName = [self.userModelDefault valueForKey:@"TT_companyName"];
    return TT_companyName;
}

- (NSString *)userId {
    NSString *TT_userId = [self.userModelDefault valueForKey:@"TT_userId"];
    return TT_userId;
}

- (NSString *)cardId {
    NSString *TT_cardId = [self.userModelDefault valueForKey:@"TT_cardId"];
    return TT_cardId;
}

- (NSString *)userName {
    NSString *TT_userName = [self.userModelDefault valueForKey:@"TT_userName"];
    return TT_userName;
}

- (NSString *)avatarUrl {
    NSString *TT_avatarUrl = [self.userModelDefault valueForKey:@"TT_avatarUrl"];
    return TT_avatarUrl;
}

- (NSString *)phone {
    NSString *TT_phone = [self.userModelDefault valueForKey:@"TT_phone"];
    return TT_phone;
}

- (NSString *)token {
    NSString *TT_token = [self.userModelDefault valueForKey:@"TT_token"];
    return TT_token;
}

- (NSString *)roleId {
    NSString *TT_roleId = [self.userModelDefault valueForKey:@"TT_roleId"];
    return TT_roleId;
}

- (NSArray *)auths {
    NSArray *TT_auths =  [self.userModelDefault valueForKey:@"auths"];
    return TT_auths;
}

- (BOOL)authPhone {
    NSString *TT_authPhone = [self.userModelDefault valueForKey:@"TT_authPhone"];
    if ([TT_authPhone isEqualToString:@"1"]) {
        return YES;
    } else {
        return NO;
    }
}

- (BOOL)authWx {
    NSString *TT_authWx = [self.userModelDefault valueForKey:@"TT_authWx"];
    if ([TT_authWx isEqualToString:@"1"]) {
        return YES;
    } else {
        return NO;
    }
}

-(NSUserDefaults *)userModelDefault {
    if (!_userModelDefault) {
        _userModelDefault = [NSUserDefaults standardUserDefaults];
    }
    return _userModelDefault;
}


- (NSString *)identifier {
    NSString *TT_identifier = [self.userModelDefault valueForKey:@"TT_identifier"];
    return TT_identifier;
}

- (NSString *)userSig {
    NSString *TT_userSig = [self.userModelDefault valueForKey:@"TT_userSig"];
    return TT_userSig;
}

- (NSString *)appidAt3rd {
    NSString *TT_appidAt3rd = [self.userModelDefault valueForKey:@"TT_appidAt3rd"];
    return TT_appidAt3rd;
}

@end
